﻿using ApplicationBase.Core.Attributes;
using IdentityService.Domain.Services;
using MediatR;

namespace IdentityService.Application.Commands
{
    //[CheckPermit(PermitDictionary.PermitAdmin)]
    public record CreatePermitCommand(long ParentId, string Name, string Description) : IRequest<CreatePermitResultModel>;

    public class CreatePermitCommandHandler : IRequestHandler<CreatePermitCommand, CreatePermitResultModel>
    {
        public readonly IPermitService _permitService;
        public CreatePermitCommandHandler(IPermitService permitService)
            => _permitService = permitService;

        public async Task<CreatePermitResultModel> Handle(CreatePermitCommand request, CancellationToken cancellationToken)
        {
            return await _permitService.CreatePermit(request.ParentId, request.Name, request.Description);
        }
    }
}
